package com.sqsxblog.navigation.fragment.view

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.navigation.NavOptions
import androidx.navigation.Navigation
import androidx.navigation.fragment.findNavController
import com.sqsxblog.navigation.R

class FourthFragment : BaseFragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View {
        return inflater.inflate(R.layout.fragment_fourth,container,false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        //返回上一页
        requireView().findViewById<Button>(R.id.back).setOnClickListener {
            findNavController().navigateUp()
        }
        //返回到指定页面
        requireView().findViewById<Button>(R.id.firstFragment).setOnClickListener {
            //这段代码返回的其实是second，但参数二传了true，因此second也被pop掉了，最终返回了first页
            findNavController().popBackStack(R.id.secondFragment,true)
        }
    }
}